﻿@{
    ViewBag.Title = Local("UCenter.DiskManagement");
    Layout = GetPath(SystemDirectory.Shared, "_Dialog.cshtml");
}

@model UserFolder
 
@if (IsValided)
{
<div class="box">
    <div class="ui-widget-header ui-corner-all nav-folder">
        <img src="@Storages.GetIconUrl(FileIconMode.X16, "folder")" align="absmiddle" /> 
        @{ 
    if (ViewBag.FileType == FileType.None)
    {
            <a href="@UCenterUrls.DialogDiskView">@Local("UCenter.DiskRoot", Self.NickName)</a>
    }
    else
    {
            <a href="@UCenterUrls.DialogDiskView?type=@ViewBag.FileType">@Local("UCenter.DiskRoot", Self.NickName)</a>
    }

    var folders = Storages.GetFolderTrees(Model.FolderID);
    if (folders != null && folders.Count > 0)
    {
        for (var i = folders.Count - 1; i >= 0; i--)
        { 
                    <text> / </text> 
            if (ViewBag.FileType == FileType.None)
            {
                    <a href="?id=@folders[i].FolderID">@folders[i].FolderName</a>
            }
            else
            {
                    <a href="?id=@folders[i].FolderID&type=@ViewBag.FileType">@folders[i].FolderName</a>
            }
        }
    }
        }
        <span style="float:right;">@Local("DiskUsage")： @Storages.GetDiskUsage().ToContentLengthString() / @Permission.MaxDiskSize.ToContentLengthString(null, 0)</span>
    </div>
    <table cellpadding="0" cellspacing="0">
        <thead class="ui-widget-header">
            <tr>
                <td>@Local("FileStorages.Name")</td>
                <td class="w160">@Local("FileStorages.LastModified")</td>
                <td class="w100">@Local("FileStorages.ContentLength")</td>
            </tr>
        </thead>
        <tbody>
        @foreach (var folder in Model.Children)
        {
        <tr class="folder-container" data="@folder.FolderID" data-type="@((int)ViewBag.FileType)">
            <td>
                <img src="@Storages.GetIconUrl(FileIconMode.X16, "folder")" align="absmiddle" /> @folder.FolderName
                <span class="action-panel">
                    @Html.ModalLink("Folder.Edit", string.Format("{0}?id={1}", UCenterUrls.DialogUpdateFolderView, folder.FolderID), 400)
                    @Html.ModalLink("Folder.Move", string.Format("{0}?id={1}", UCenterUrls.DialogMoveFolderView, folder.FolderID), 400)
                    @Html.AjaxLink(HttpAction.Folder, "FileStorages.Delete", new { did = folder.FolderID })
                </span>
            </td>
            <td class="w160">@folder.LastModified.ToLocalDateTimeString()</td>
            <td class="w100">@folder.ContentLength.ToContentLengthString()</td>
        </tr>
        }
        @foreach (var file in Model.Files)
        {
            if (ViewBag.FileType == FileType.None || (file.FileType & ViewBag.FileType) == file.FileType)
            {
            <tr class="file-mark" data="@file.FileID?/@file.FullName">
                <td>
                    <img src="@Storages.GetFileIconUrl(FileIconMode.X16, file.Extension)" align="absmiddle" /> @file.FullName
                    <span class="action-panel">
                        @Html.ModalLink("Folder.Edit", string.Format("{0}?id={1}", UCenterUrls.DialogUpdateFileView, file.FileID), 400)
                        @Html.ModalLink("Folder.Move", string.Format("{0}?id={1}", UCenterUrls.DialogMoveFileView, file.FileID), 400)
                        @Html.AjaxLink(HttpAction.File, "FileStorages.Delete", new { did = file.FileID })
                        @if(file.FileType == FileType.Image)
                        {
                            @Html.ModalLink("UserFile.ImageView", string.Format("{0}?id={1}", UCenterUrls.DialogImageView, file.FileID), 400)
                        }
                    </span>
                </td>
                <td class="w160">@file.LastModified.ToLocalDateTimeString()</td>
                <td class="w100">@file.ContentLength.ToContentLengthString()</td>
            </tr>
            }
        }
        </tbody>
    </table>
</div>

<div class="box">
    <form enctype="multipart/form-data" method="post">
        <input type="file" name="UploadFile" />
        <button class="button">@Local("UserFile.Upload")</button>
    </form>
    @Html.ModalLink("Folder.New", UCenterUrls.DialogFolderView, 350, new { @class = "button" })
</div>

<script type="text/javascript">
    $(function () {
        $('.file-mark').dblclick(function () {
            parent.callback($(this).attr('data'));
            parent.closeModal();
        });
    });
</script>
}